package com.asurplus.xjar.utils;

import io.xjar.boot.XBoot;
import io.xjar.jar.XJar;

import java.io.File;

/**
 * jar包加密处理工具类
 *
 * @author Asurplus
 */
public class XjarUtil {

    /**
     * 密码
     */
    private static final String PASSWORD = "123456";

    /**
     * boot-jar包加密
     *
     * @param plaintext 加密前的jar包文件
     * @param encrypted 加密后的jar包文件
     * @param password
     * @throws Exception
     */
    public static void encryptBoot(File plaintext, File encrypted, String password) throws Exception {
        XBoot.encrypt(plaintext, encrypted, password);
    }

    /**
     * boot-jar包解密
     *
     * @param encrypted 解密前的jar包
     * @param decrypted 解密后的jar包
     * @param password
     * @throws Exception
     */
    public static void decryptBoot(File encrypted, File decrypted, String password) throws Exception {
        XBoot.encrypt(encrypted, decrypted, password);
    }

    /**
     * Jar包加密
     *
     * @param plaintext 加密前的jar包文件
     * @param encrypted 加密后的jar包文件
     * @param password
     * @throws Exception
     */
    public static void encryptJar(File plaintext, File encrypted, String password) throws Exception {
        XJar.encrypt(plaintext, encrypted, password);
    }

    /**
     * Jar包解密
     *
     * @param encrypted 解密前的jar包
     * @param decrypted 解密后的jar包
     * @param password
     * @throws Exception
     */
    public static void decryptJar(File encrypted, File decrypted, String password) throws Exception {
        XJar.decrypt(encrypted, decrypted, password);
    }

    /**
     * boot-jar包加密
     */
    public static void main(String[] args) {
        try {
            File plaintext = new File("E:\\xjar\\加密前\\test.jar");
            File encrypted = new File("E:\\xjar\\加密后\\test.jar");
            // boot的jar包加密
            encryptBoot(plaintext, encrypted, PASSWORD);
            System.out.println("加密成功");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("加密失败");
        }
    }
}
 
 
 